package com.ruoyi.eqmonitor.mapper;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.eqmonitor.domain.OptDevice;
import com.ruoyi.eqmonitor.domain.OptDeviceAlarm;
import com.ruoyi.eqmonitor.dtos.*;
import com.ruoyi.eqmonitor.vo.BszsVo;
import com.ruoyi.eqmonitor.dtos.BszsSubclassDto;
import com.ruoyi.eqmonitor.dtos.CsyzSubclassDto;
import com.ruoyi.eqmonitor.vo.CsyzVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;


/**
 * @author ruoyi
 * @date 2022-11-25
 */
public interface OptDeviceAlarmMapper extends BaseMapper<OptDeviceAlarm>{

    public List<OptDeviceAlarm> selectOptDeviceAlarmList(AlarmSearchInput optDeviceAlarm);

    public OptDeviceAlarm selectOptDeviceAlarmById(Long id);

    List<OptDeviceAlarmDto> listAndDispatch(AlarmSearchInput optDeviceAlarm);

    List<OptDeviceAlarmDto> listVo(AlarmSearchInput optDeviceAlarm);

    /**
     * 运维管理使用 -- 按时间周期搜索
     */
    List<OptDeviceAlarmDto> deviceList(AlarmSearchInput optDeviceAlarm);

    /**
     * 根据报警ids查询最新流程状态列表
     * @param ids 报警ids
     * @return 最新流程状态列表, 只返回id(报警id),businessId,activityName,activityFlag
     */
    List<OptDeviceAlarmDto> recordListByIds(@Param("ids") List<Long> ids);

	public List<OptDeviceAlarmDto> selectOptDeviceAlarmClogList(OptDeviceAlarmDto optDeviceAlarm);

    public OptDeviceAlarmDto selectOptDeviceAlarmClogInfo(Long id);

    Long mySelectCount(@Param("deviceTypes") List<String> deviceTypes,
                       @Param("areaCodes") List<String> areaCodes,
                       @Param("areaName") String areaName);

    Long mySelectSumCount(@Param("deviceTypes") List<String> deviceTypes,
                          @Param("areaCode") String areaCode);

    List<Map<String, Object>> quantityStatistics(OptDeviceAlarmDto dto);

    List<CsyzSubclassDto> selectGWMY();

    List<CsyzSubclassDto> myCount(@Param("deviceTypes") List<String> deviceTypes,
                                  @Param("phenomenons") List<String> phenomenons,
                                  @Param("confirmAlarms") List<String> confirmAlarms,
                                  @Param("DISTINCT") int DISTINCT);

    List<BszsSubclassDto> mySelectCountGroupByAreaName(@Param("deviceTypes") List<String> deviceTypes,
                                                       @Param("alarmPhenomenons") List<String> alarmPhenomenons);

    OptDeviceAlarmDto maxSewageAlarmByDeviceCode(@Param("deviceCode") String deviceCode, @Param("alarmPhenomenon") String alarmPhenomenon);

    OptDeviceAlarmDto minSewageAlarmByDeviceCode(@Param("deviceCode") String deviceCode, @Param("alarmPhenomenon") String alarmPhenomenon);

    List<OptDeviceAlarmDto> selectRiverwayAlarm(@Param("beginTime") String beginTime,
                                            @Param("endTime") String endTime,
                                            @Param("deviceCodes") List<String> deviceCodes, @Param("siteNames") List<String> siteNames,
                                            @Param("deviceTypes") List<String> deviceTypes);

    List<CsyzVo> selectCsyzBackstage(@Param("areaName")String areaName,
                                     @Param("beginTime")String beginTime,
                                     @Param("endTime")String endTime);

    List<BszsVo> selectBSZSBackstage(@Param("areaName")String areaName,
                                     @Param("beginTime")String beginTime,
                                     @Param("endTime")String endTime,
                                     @Param("tableName")String tableName);

    Integer getDayAlarmCount(@Param("deviceCode")String deviceCode,
                          @Param("startTime")String startTime,
                          @Param("alarmPhenomenon")Integer alarmPhenomenon);

    List<OptDevice> backstageDeviceCall(@Param("query") BszsVo query,
                                        @Param("deviceTypeList")List<String> deviceTypeList,
                                        @Param("alarmPhenomenonList")List<Integer> alarmPhenomenonList,
                                        @Param("confirmAlarmList")List<Integer> confirmAlarmList);
    //排除井盖
    @Select("select count(1) from opt_device_alarm where device_code in (select device_code from opt_device where site_id=#{siteId} and device_type !='SJ500-L-Y0') and last_alarm_time>=#{startTime} and last_alarm_time<#{endTime} and persistent_status = '0'")
    int countAlarmCount(@Param("siteId") String siteId,@Param(("startTime")) LocalDateTime startTime,@Param(("endTime")) LocalDateTime endTime);
}
